﻿/*
*   学员信息页面
*/
angular.module('jisuStuHome')
.controller('myfollowcolnumController', ['$scope', '$rootScope', '$state', 'StuRequestTrain', 'interlocutionservice', 'sysUserInfo', 'Msg', 'T', 'LS', function ($scope, $rootScope, $state, ST, IS, sysUserInfo, Msg, T, LS) {

    //初始
    $scope.init = function () {
        $rootScope.parstr = "home.interlocution";
        $rootScope.twoparstr = "home.interlocution.myfollowcolnum";
        //查询我关注专栏的参数
        $scope.params = {
            knowledgeid: "",
            orgid: sysUserInfo.getuserinfo().organization_ID,
            userid: sysUserInfo.getuserinfo().user_ID,
            searchTxt: "",
            pageIndex: 1,
            pageSize: 10,
            type: 3
        };
        $scope.searchTxt = "";
        $scope.knowledgeid = "";
    }
    //返回主页，专栏列表
    $scope.backHome = function () {
        $rootScope.twoparstr = "home.interlocution";
        $rootScope.parstr = "home.interlocution";
        $state.go($rootScope.twoparstr);
    }
    //打开问答列表
    //路由跳转
    $scope.openQuestList = function (item) {
        $rootScope.twoparstr = "home.interlocution.questionlist";
        $rootScope.parstr = "home.interlocution";
        LS.setLS(sysUserInfo.getuserinfo().user_ID + '_col', item);
        $state.go($rootScope.twoparstr);
    }
    //搜索
    $scope.searchByTxt = function () {
        $scope.getList(); //我关注的专栏
    }
    //取消关注专栏
    $scope.followCollnum = function (item) {
        IS.addFollowSC({ columnId: item.columnId, userId: sysUserInfo.getuserinfo().user_ID }).then(function (response) {
            if (response.errorcode == "0") {
                Msg.success("取消成功");
                $scope.List.forEach(function (data, index) {
                    if (data.columnId == item.columnId) {
                        $scope.List.splice(index, 1);
                    }
                });
                $rootScope.TJInfo.followzlNum = $rootScope.TJInfo.followzlNum - 1; //修改收藏专家数量
            } else {
                Msg.error("操作异常!")
            }
        }, function errorCallback() {
            $scope.Loading = false;
            console.log("连接服务器失败！");
        });
    }
    //*******************************专栏************************************/
    //排序筛选，默认最新
    $scope.cutDesc = function (index) {
        $scope.params.orderby = index;
        $scope.getList();
    }
    //查询专栏列表
    $scope.getList = function () {
        $scope.params.knowledgeid = $scope.knowledgeid;

        IS.findStuSclist($scope.params).then(function (response) {
            $scope.Loading = false;
            if (response.errorcode == "0") {
                $scope.List = response.datas;
                $scope.paginationConf.totalItems = response.numCount;
                $scope.paginationConf.currentPage = response.pageIndex;
            } else {
                Msg.error("查询异常!")
            }
        }, function errorCallback() {
            $scope.Loading = false;
            console.log("连接服务器失败！");
        });
    }

    //配置分页
    $scope.paginationConf = {
        currentPage: 1, //$location.search().currentPage ? $location.search().currentPage :  当前页码
        totalItems: 0,  // 总的记录数
        itemsPerPage: 10, // 每页显示多少条        
        perPageOptions: [10, 20],   // 每页显示记录数        
        onChange: function () {
            $scope.paginationConf.currentPage = $scope.paginationConf.currentPage == 0 ? 1 : $scope.paginationConf.currentPage;
            $scope.params.pageIndex = $scope.paginationConf.currentPage;
            $scope.params.pageSize = $scope.paginationConf.itemsPerPage;
            $scope.getList();
        }
    };
    /***********************************************初始*****************************************************/
    //初始
    $scope.init();
} ]);




